<template>
  <div class="top">
    <div class="left">
      <span class="lbtn" @click="goHome">首页</span>
    </div>
    <div class="center">
      <div class="title">智慧旅游可视化大数据展示平台</div>
    </div>
    <div class="right">
      <span class="rbtn">统计报告</span>
      <span class="time">当前时间: {{ time }}</span>
    </div>
  </div>
</template>

<script setup lang="ts">
  import { onBeforeUnmount, onMounted, ref } from 'vue'
  import { useRouter } from 'vue-router'
  import moment from 'moment'

  const $router = useRouter()
  const time = ref<string>(moment().format('YYYY年MM月DD日 hh:mm:ss'))
  const timer = ref<number | null>(null)
  function goHome() {
    $router.push('/home')
  }

  onMounted(() => {
    timer.value = setInterval(() => {
      // 获取实时时间
      time.value = moment().format('YYYY年MM月DD日 hh:mm:ss')
    }, 1000)
  })

  onBeforeUnmount(() => {
    timer.value && clearInterval(timer.value)
  })
</script>

<style lang="scss" scoped>
  .top {
    display: flex;
    width: 100%;
    height: 40%;
    .left {
      flex: 1;
      background-image: url(../../images/dataScreen-header-left-bg.png);
      background-repeat: no-repeat;
      background-size: cover;
      .lbtn {
        width: 150px;
        height: 40px;
        line-height: 40px;
        float: right;
        background: url(../../images/dataScreen-header-btn-bg-l.png) no-repeat;
        background-size: 100% 100%;
        text-align: center;
        color: #29fcff;
        font-size: 20px;
        cursor: pointer;
      }
    }
    .center {
      flex: 2;
      .title {
        width: 100%;
        height: 74px;
        background: url(../../images/dataScreen-header-center-bg.png) no-repeat;
        background-size: 100% 100%;
        text-align: center;
        line-height: 74px;
        color: #29fcff;
        font-size: 30px;
      }
    }
    .right {
      flex: 1.5;
      background-image: url(../../images/dataScreen-header-left-bg.png);
      background-repeat: no-repeat;
      background-size: cover;
      display: flex;
      justify-content: space-between;
      align-items: center;
      .rbtn {
        width: 150px;
        height: 40px;
        line-height: 40px;
        background: url(../../images/dataScreen-header-btn-bg-r.png) no-repeat;
        background-size: 100% 100%;
        text-align: center;
        color: #29fcff;
        font-size: 20px;
      }
      .time {
        color: #29fcff;
        font-size: 20px;
        margin-right: 10px;
      }
    }
  }
</style>
